#include <iostream>
#include <algorithm>

using namespace std;

int n, m;
const int N = 1010;

int f[N][N];

int main()
{
    string a, b;
    cin >> a >> b;
    for (int i = 1; i <= a.size(); ++i)
    {
        for (int j = 1; j <= b.size(); ++j)
        {
            f[i][j] = max(f[i - 1][j], f[i][j - 1]);
            if (a[i - 1] == b[j - 1])
            {
                f[i][j] = max(f[i][j], f[i - 1][j - 1] + 1);
            }
        }
    }
    cout << f[a.size()][b.size()];
    return 0;
}
